package com.chen.nongansampling.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.chen.nongansampling.R;
import com.chen.nongansampling.adapter.ListviewTextAdapter;
import com.chen.nongansampling.app.BaseApplication;
import com.chen.nongansampling.bean.ui.ExpandListView;
import com.chen.nongansampling.bean.ui.ListviewBean;
import com.chen.nongansampling.fragment.ChangePasswordFragment;
import com.chen.nongansampling.ui.login.LoginActivity;
import com.chen.nongansampling.utils.StorageUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SettingActivity extends AppCompatActivity {

    @BindView(R.id.unLogin)
    Button unLogin;
    @BindView(R.id.unLoginFanhui)
    Button fanhui;
    Bundle savedInstanceState;
    @BindView(R.id.setting_listview)
    ExpandListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.savedInstanceState = savedInstanceState;
        setContentView(R.layout.activity_setting);
        ButterKnife.bind(this);

        ListviewBean<String> list1 = new ListviewBean();
        list1.setData(BaseApplication.getAccount().getLoginName());
        list1.setImageSrc(R.mipmap.zhanghao);
        list1.setName("账号");


        ListviewBean<String> list2 = new ListviewBean();
        list2.setName("检测师姓名");
        list2.setImageSrc(R.mipmap.setting_user_name);
        list2.setData(BaseApplication.getAccount().getLoginName());


        ListviewBean<String> list3 = new ListviewBean();
        list3.setData(BaseApplication.getAccount().getDepartmentName());
        list3.setImageSrc(R.mipmap.setting_department);
        list3.setName("所属单位");


        List<ListviewBean> list = new ArrayList<>();
        list.add(list1);
        list.add(list2);
        list.add(list3);
        //   list.add(list4);

        ListviewTextAdapter listviewTextAdapter = new ListviewTextAdapter(list, getApplicationContext(), true);
        //     listviewTextAdapter.getView(3,getApplication(),false).

        listView.setAdapter(new ListviewTextAdapter(list, getApplicationContext(), true));

    }

    @OnClick(R.id.unLogin)
    public void onClick() {
        StorageUtil.setLoginStatus(getApplicationContext(), false);
        Intent intent = new Intent(this, LoginActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        finish();
    }
    @OnClick(R.id.unLoginFanhui)
    public void onClickf() {

        finish();
    }
    @OnClick(R.id.change_password)
    public void onClickChangePassword() {
        Log.d("onClickChangePassword", "onClickChangePassword");
        //  StorageUtil.setLoginStatus(getApplicationContext(),false);
//        Intent intent=new Intent(this, LoginActivity.class);
//        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
//        startActivity(intent);
//        finish();
//            getSupportFragmentManager().beginTransaction()
//                    .add(R.id.container, ChangePasswordFragment.newInstance())
////                .addToBackStack("SampleFragment")
//                    .commitNow();
//        if (savedInstanceState == null) {

        getFragmentManager().beginTransaction()
                .add(R.id.setting_container, new ChangePasswordFragment())
//                .addToBackStack("SampleFragment")
                .commit();
        //    FragmentManager fragmentManager=getF
//        Intent show=new Intent(SettingActivity.this,ChangePasswordFragment.class);
//
//        show.putExtra("grxx",1);
//        startActivity(show);
//        finish();


//        getSupportFragmentManager().beginTransaction()
//                .add(R.id.container, SampledFragment.newInstance())
////                .addToBackStack("SampleFragment")
//                .commitNow();


//        }

//            Intent intent =new Intent(this,SettingActivity.class);
//        Intent intent = new Intent(this, SettingActivity.class);
//        startActivity(intent);


    }

}
